﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace aboveXWords.GUI
{
  [Serializable]
  public class Handle
  {
    private readonly Image m_bmpHandle = new Bitmap(8, 8);
    private PointF m_point;

    public Handle(Square square)
    {
      Square = square;
    }

    protected Square Square { get; set; }

    internal PointF PointF
    {
      get { return m_point; }
      set
      {
        m_point = value;
        Rectangle = new RectangleF(m_point.X - m_bmpHandle.Width/2.0f,
                                   m_point.Y - m_bmpHandle.Height/2.0f,
                                   m_bmpHandle.Width,
                                   m_bmpHandle.Height);
      }
    }

    protected internal RectangleF Rectangle { get; set; }

    internal float Width
    {
      get { return m_bmpHandle.Width; }
    }

    internal float Height
    {
      get { return m_bmpHandle.Height; }
    }

    internal virtual bool Contains(PointF mousePosition)
    {
      return Rectangle.Contains(mousePosition);
    }

    internal virtual void Create(GraphicsPath path)
    {
      path.AddRectangle(Rectangle);
    }
  }
}